#include "ProjectTextBlood.h"

ProjectTextBlood::ProjectTextBlood(const std::string &name, CC::Scene *scene)
	: ProjectSandbox(name, scene)
{
	CC_INFO("-----ProjectTextBlood----\n");
}

ProjectTextBlood::~ProjectTextBlood()
{
}

void ProjectTextBlood::OnAttach()
{
    ProjectSandbox::OnAttach();

    CC::Shader* shader = CC::ResourceManager::LoadShader("Renderer2D_QuadTextBlood", ("Renderer2D_QuadTextBlood"), ("Renderer2D_QuadTextBlood"));
    CC::ShaderComponent* shader_sc = new CC::ShaderComponent(shader);

    CC::Texture2D* textexture = CC::ResourceManager::LoadTexture(PATHCONFIG("assets/textures/text.png"), "textpng");

    CC::Custom2DMaterialComponent* custom2DMaterialComponent = new CC::Custom2DMaterialComponent();
    custom2DMaterialComponent->datas["TextureSize0"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float2, GetWidth(), GetHeight());
    custom2DMaterialComponent->datas["Time"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float, 0.0f);
    custom2DMaterialComponent->datas["TextTexture"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Texture, textexture);
    custom2DMaterialComponent->datas["TextColor"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float4, 173.0f/255.0f, 0.0f / 255.0f, 0.0f / 255.0f, 1.0f);
    custom2DMaterialComponent->datas["Lines[0]"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float4, 828.0f, 853.0f, 828.0f, 1110.0f);//x1,y1, x2,y2
    custom2DMaterialComponent->datas["Lines[1]"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float4, 1033.0f, 850.0f, 1033.0f, 1210.0f);//x1,y1, x2,y2
    custom2DMaterialComponent->datas["Lines[2]"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float4, 1461.0f, 853.0f, 1461.0f, 1310.0f);//x1,y1, x2,y2
    custom2DMaterialComponent->datas["Lines[3]"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float4, 1850.0f, 840.0f, 1850.0f, 1110.0f);//x1,y1, x2,y2
    custom2DMaterialComponent->datas["Lines[4]"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float4, 1146.0f, 700.0f, 1146.0f, 900.0f);//x1,y1, x2,y2
    custom2DMaterialComponent->datas["Lines[5]"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float4, 1635.0f, 641.0f, 1635.0f, 972.0f);//x1,y1, x2,y2
    custom2DMaterialComponent->datas["Lines[6]"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float4, 1242.9f, 847.0f, 1242.9f, 1000.0f);//x1,y1, x2,y2
    custom2DMaterialComponent->datas["Lines[7]"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float4, 1361.0f, 847.0f, 1361.0f, 1000.0f);//x1,y1, x2,y2
  
    GetNode()->AddComponent<CC::ShaderComponent>(shader_sc);
    GetNode()->AddComponent<CC::Custom2DMaterialComponent>(custom2DMaterialComponent);

    //GetAnimObj()->SetAnimTime(10000.0);
}

void ProjectTextBlood::OnDetach()
{
    ProjectSandbox::OnDetach();
}

void ProjectTextBlood::OnUpdate(CC::Timestep ts, std::string renderscene)
{        
    ProjectSandbox::OnUpdate(ts, renderscene);

    if (0 == GetShowWin()) return;

    auto tran = GetNode()->GetComponent<CC::TransformComponent>(CC::ComponentType_Transform);
    tran->Translation = glm::vec3(0.0, 0.0, 0.0);
    tran->Scale = glm::vec3(GetWidth(), GetHeight(), 0.0);

    auto custom2DMaterialComponent = GetNode()->GetComponent<CC::Custom2DMaterialComponent>(CC::ComponentType_Custom2DMaterial);
    custom2DMaterialComponent->datas["TextureSize0"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float2, GetWidth(), GetHeight());

    time += ts.GetMilliseconds() * 0.001;
    //custom2DMaterialComponent->datas["Time"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float, GetAnimObj()->GetCurrentValue());
    custom2DMaterialComponent->datas["Time"] = CC::Custom2DMaterialComponent::DataInfo(CC::Custom2DMaterialComponent::DataType_Float, time);

}